
<form method="post" action="/oss/?r=white/doAdd">
    <{include file='../common_params.tpl'}>

    <div class="box box-black">
        <div class="box-body">
            <table class="table table-bordered">
                <colgroup>
                    <col style="width: 20%;"></col>
                    <col style="width: 80%;"></col>
                </colgroup>
                
                <tr>
                    <th class="th-label">专服</th>
                    <td>
                        <select class="form-control inline" name="special_id">
                        	<{foreach from=$specialList item=item key=key}>
                        		<option value="<{$key}>"><{$item}></option>
                        	<{/foreach}>
                        </select>
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">渠道</th>
                    <td>
                        <select class="form-control inline" name="channel_id">
                        	<option value="">请选择</option>
                        	<!--<{foreach from=$channelList item=item key=key}>
                        		<option value="<{$key}>"><{$item}></option>
                        	<{/foreach}>-->
                        </select>
                    </td>
                </tr>

                <tr>
                    <th class="th-label">账号</th>
                    <td>
                        <input type="text" name="openid" class="form-control inline" placeholder="" />
                    </td>
                </tr>
                
                <tr>
                    <th class="th-label">使用者姓名</th>
                    <td>
                        <input type="text" name="username" class="form-control inline" placeholder="" />
                    </td>
                </tr>
                
                


            </table>
        </div>

        <div class="box-footer">
            <a href="javascript:history.go(-1);" class="btn btn-default">返回</a>
            <button type="submit" name="sub" class="btn btn-default pull-right">保存</button>
        </div>
    </div>
</form>

<script type="text/javascript">
    $(function(){
    	$(document).on('change','select[name = "special_id"]',function(){
        	var g = $('input[name="g"]').val();
	        var url = '?r=specialServer/getChannel&g='+g;
        	
        	var special_id = $(this).val();
        	if(special_id == ''){
				var option = '';	
				option += "<option value=''>请选择</option>";
				$('select[name="channel_id"]').empty();
				$('select[name="channel_id"]').append(option);
				return false;
			}
        	
          	$.ajax({
	        	type : 'POST',
	        	url : url,
	        	async:false,
	        	data : {'special_id':special_id},
		        dataType :'JSON',
		        success : function(res){
		        	if(res.status){	
		        		var option = '';	
					    option += "<option value=''>请选择</option>";
					    for (var i=0;i<res.data.length;i++){
					    	var selected = '';
						    option += "<option "+selected+" value='"+res.data[i]['id']+"'>"+res.data[i]['channel_name']+"</option>";
					    }
					    $('select[name="channel_id"]').empty();
					    $('select[name="channel_id"]').append(option);
					   //layer.alert('设置成功', {icon: 1, skin: 'layui-layer-molv'});
			        }else{
			        	//layer.alert('设置失败', {icon: 2, skin: 'layui-layer-molv'});
			        	var option = '';	
					    option += "<option value=''>请选择</option>";
					    $('select[name="channel_id"]').empty();
					    $('select[name="channel_id"]').append(option);
			        }
		        }
	        });
        });
    	
    	
    	$('button[name="sub"]').click(function(){
    		var special_id = $('select[name="special_id"]').val();
        	if(special_id == ''){
        		layer.alert('请选择专服', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
    		var channel_id = $('select[name="channel_id"]').val();
        	if(channel_id == ''){
        		layer.alert('请选择渠道', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var openid = $('input[name="openid"]').val();
        	if(openid == ''){
        		layer.alert('请填写账号', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
        	
        	var username = $('input[name="username"]').val();
        	if(username == ''){
        		layer.alert('请填写使用者姓名', {icon: 2, skin: 'layui-layer-molv'});
            	return false;
        	}
            
            
        });
    });
</script>